{extend name="public:layout" /}
{block name="title"}创建行程单{/block}
{block name="head"}
<script src="/public/plugins/template/template.js"></script>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-hand-o-right"></i>
                    <a href="{:url('system/op/index',['mid'=>$Request.param.mid])}">客户预订列表</a>
                </li>
                <li class="active">创建行程单</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="alert alert-warning">
                <p>注意;创建行程单后，该条预订信息将不允许再进行编辑，只可以查询和删除!</p>
            </div>
            <form method="post" class="form-horizontal" id="form">
                <input type="hidden" name="pre_aid" value="{$preinfo.aid}" />
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">订单客户</label>
                    <div class="col-sm-10">
                        <p class="form-control-static">{$preinfo.title}</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">出发时间</label>
                    <div class="col-sm-4">
                        <input class="form-control laydatetime" type="text" readonly placeholder="" name="order_start_time" value="{$preinfo.begin_time}" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">收车时间</label>
                    <div class="col-sm-4">
                        <input class="form-control laydatetime" type="text" readonly placeholder="" name="order_end_time" value="{$preinfo.end_time}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">订单费用</label>
                    <div class="col-sm-4">
                        <p class="form-control-static">{$preinfo.order_money}</p>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">用车数量</label>
                    <div class="col-sm-4">
                        <p class="form-control-static">{$preinfo.use_car_num}</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">选择车辆</label>
                    <div class="col-sm-5">
                        <input class="form-control" type="text" placeholder="选择车辆" readonly name="car_sn" value="" datatype="*" />
                    </div>
                    <div class="col-sm-1">
                        <button type="button" class="btn btn-info" onclick="selectCar();">选择车辆</button>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">指派车辆</label>
                    <div class="col-sm-10">
                        <div id="car-table"></div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">备注</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" rows="3" name="fleet_desc" ></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" id="btnSub" type="button">保存</button>
                        <a href="{:url('index',['mid'=>$Request.param.mid])}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script id="car-table-tpl" type="text/html">
    <table class="table table-condensed">
        <tr>
            <th>车辆</th>
            <th>订单费用</th>
            <th>已付款</th>
            <th>出发地</th>
            <th>目的地</th>
            <th>导游/联系人</th>
            <th>导游电话</th>
            <th>接团时间</th>
        </tr>
        {{ each cars }}
        <tr>
            <td nowrap>
                {{ $value.car_sn }} {{ if $value.is_self!=1 }}（外）{{ /if }}
                <input type="hidden" name="cararr[{{ $value.car_sn }}][car_sn]" class="form-control" value="{{ $value.car_sn }}" datatype="*" />
            </td>
            <td>
                <input type="text" name="cararr[{{ $value.car_sn }}][order_charge]" class="form-control" placeholder="订单金额" value="" datatype="*" />
                {{ if $value.is_self!=1 }}
                <input type="text" name="cararr[{{ $value.car_sn }}][diff_money]" class="form-control" placeholder="差价金额" value="0" />
                {{ /if }}
            </td>
            <td><input type="text" name="cararr[{{ $value.car_sn }}][order_advance]" class="form-control" value="0" datatype="*" /></td>
            <td><input type="text" name="cararr[{{ $value.car_sn }}][order_start_adress]" class="form-control" value="" datatype="*" /></td>
            <td><input type="text" name="cararr[{{ $value.car_sn }}][order_end_adress]" class="form-control" value="" datatype="*" /></td>
            <td><input type="text" name="cararr[{{ $value.car_sn }}][guide]" class="form-control" value="" /></td>
            <td><input type="text" name="cararr[{{ $value.car_sn }}][guide_tel]" class="form-control" value="" /></td>
            <td><input type="text" name="cararr[{{ $value.car_sn }}][begin_time]" class="form-control laydatetime" value="" datatype="*" /></td>
        </tr>
        {{ /each }}
    </table>
</script>
<script type="text/javascript">
    $(function () {
        iCheck();
        formatDate();
        ajaxSubForm('#btnSub');
    });
    function selectCar() {
        var btime=$("input[name='order_start_time']").val();
        var etime=$("input[name='order_end_time']").val();
        if(btime=='' || etime==''){
            alert('请选择出发结束时间！');
            return false;
        }
        top.layer.open({
            title: '选择车辆',
            type: 2,
            area: ['1000px', '450px'],
            content: '/system/logic.select/car.html?btime='+btime+'&etime='+etime,
            btn:["选择","取消"],
            yes:function (index) {
                var is_self = top.layer.getChildFrame('#is_self', index);
                var cars = top.layer.getChildFrame('#cars', index);
                var is_self_val = is_self.val().split(',');
                var cars_val = cars.val().split(',');
                /**
                 [
                 {'car_sn':'车牌号',''is_self':1111},
                 {'car_sn':'车牌号',''is_self':1111},
                 {'car_sn':'车牌号',''is_self':1111},
                 ]
                 */
                var cardata=[];
                for($i=0;$i<cars_val.length;$i++){
                    cardata.push({"car_sn":cars_val[$i],"is_self":is_self_val[$i]});
                }
                var data={"cars":cardata};
                var carhtml = template('car-table-tpl',data);
                $("input[name='car_sn']").val(cars_val);
                $('#car-table').html(carhtml);
                formatDate();
                top.layer.close(index);
            }
        });
    }
</script>
{/block}